package ufpr.mestrado.ais.experiments;

import java.io.IOException;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;

import jmetal.base.Algorithm;
import jmetal.base.Problem;
import jmetal.experiments.Experiment;
import jmetal.experiments.Settings;
import jmetal.util.JMException;
import ufpr.mestrado.ais.experiments.settings.VIS_Settings;

public class VISStudy extends Experiment {

	/**
	 * Configures the algorithms in each independent run
	 * 
	 * @param problem
	 *            The problem to solve
	 * @param problemIndex
	 * @param algorithm
	 *            Array containing the algorithms to run
	 * @throws ClassNotFoundException
	 */
	public synchronized void algorithmSettings(Problem problem,
			int problemIndex, Algorithm[] algorithm)
			throws ClassNotFoundException {
		try {
			int numberOfAlgorithms = algorithmNameList_.length;

			Properties[] parameters = new Properties[numberOfAlgorithms];

			for (int i = 0; i < numberOfAlgorithms; i++) {
				parameters[i] = new Properties();
			} // for

			if ((!paretoFrontFile_[problemIndex].equals(""))
					|| (paretoFrontFile_[problemIndex] == null)) {
				for (int i = 0; i < numberOfAlgorithms; i++)
					parameters[i].setProperty("paretoFrontFile_",
							paretoFrontFile_[problemIndex]);
			} // if

			for (int i = 0; i < numberOfAlgorithms; i++)
				algorithm[i] = new VIS_Settings(problem)
						.configure(parameters[i]);

		} catch (IllegalArgumentException ex) {
			Logger.getLogger(VISStudy.class.getName()).log(Level.SEVERE, null,
					ex);
		} catch (IllegalAccessException ex) {
			Logger.getLogger(VISStudy.class.getName()).log(Level.SEVERE, null,
					ex);
		} catch (JMException ex) {
			Logger.getLogger(VISStudy.class.getName()).log(Level.SEVERE, null,
					ex);
		}
	} // algorithmSettings

	public static void main(String[] args) throws JMException, IOException {
		VISStudy exp = new VISStudy(); // exp = experiment

		exp.experimentName_ = "VISStudy";

		exp.algorithmNameList_ = new String[] { "VIS" };

		exp.problemList_ = new String[] { "ZDT6" };

		exp.paretoFrontFile_ = new String[] { "ZDT6.pf" };

		exp.indicatorList_ = new String[] { "HV", "SPREAD", "IGD", "EPSILON" };

		int numberOfAlgorithms = exp.algorithmNameList_.length;

		exp.experimentBaseDirectory_ = System.getProperty("user.home")
				+ "/mestrado/testes/jmetal/" + exp.experimentName_;

		exp.paretoFrontDirectory_ = System.getProperty("user.home")
				+ "/AIOPMO/fronts";

		exp.algorithmSettings_ = new Settings[numberOfAlgorithms];

		exp.independentRuns_ = 40;

		// Run the experiments
		int numberOfThreads;
		exp.runExperiment(numberOfThreads = 2);

		// Generate latex tables (comment this sentence is not desired)
		exp.generateLatexTables();

		// Configure the R scripts to be generated
		int rows;
		int columns;
		String prefix;
		String[] problems;

		rows = 2;
		columns = 3;
		prefix = new String("Problems");
		problems = exp.problemList_;

		boolean notch;
		exp.generateRBoxplotScripts(rows, columns, problems, prefix,
				notch = true, exp);
		exp.generateRWilcoxonScripts(problems, prefix, exp);
	} // main
} // VISStudy

